package guoanmaker.operator.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorLuckdraw;

public interface OperatorLuckdrawRepository extends JpaRepository<OperatorLuckdraw, String>, JpaSpecificationExecutor<OperatorLuckdraw> {
	@Query("select oae from OperatorLuckdraw oae where oae.activityId=:activityId and"
			+ "((oae.timeStart<=NOW() and oae.timeEnd>NOW())"
			+ "or(oae.timeStart =null and oae.timeEnd =null)) and ((oae.maxDrawNum != oae.drawnum ) or (oae.number=0 and maxDrawNum =0)) ")
	public List<OperatorLuckdraw> queryOperatorLuckdrawByActivityId(@Param("activityId")String activityId);
	@Transactional
	@Modifying
	@Query("UPDATE  OperatorLuckdraw SET drawnum =drawnum+1 where Id=:Id ")
	public void  updateOperatorLuckdraw(@Param("Id")String Id);
	@Query("select oae from OperatorLuckdraw oae where oae.activityId=:activityId ")
	public List<OperatorLuckdraw> queryAllLuckdrawByActivityId(@Param("activityId")String activityId);

}
